package edu.faytechcc.csc.database;

import java.sql.*;   // Needed for JDBC classes

/**
 * This class creates the Comment Table.
 * 
 * @author Stephanie Mckenzie and Jasmin Pastari
 */
public class CreateCommentTable
{

    public static void main(String[] args)
    {
        // Create a named constant for the URL.
        // NOTE: This value is specific for Java DB.
        final String DB_URL = "jdbc:derby:ARGDB;create=false";

        try
        {
            // Create a connection to the database.
            Connection conn =
                    DriverManager.getConnection(DB_URL);

            // Build the Coffee table.
            buildCommentTable(conn);

            // Close the connection.
            conn.close();
        } catch (Exception ex)
        {
            System.out.println("ERROR: " + ex.getMessage());
        }
    }

    /**
     * The buildCommentTable method creates the Comment table and adds some rows
     * to it.
     */
    public static void buildCommentTable(Connection conn)
    {
        try
        {
            // Get a Statement object.
            Statement stmt = conn.createStatement();
            try
            {
                // Drop the table.
                stmt.execute("DROP TABLE Comment_Table");
                System.out.println("Comment table dropped.");
            } catch (Exception ex)
            {
            }
            // Create the table.
            stmt.execute("CREATE TABLE Comment_Table ("
                    + "UNIQ_ID VARCHAR(6) NOT NULL PRIMARY KEY, "
                    + "ENG_TITLE(30) NOT NULL "
                    + "USER_NAME VARCHAR(30) NOT NULL "
                    + "COMMENT VARCHAR(300) "
                    + "RATING VARCHAR(30) "
                    + ")");

            System.out.println("Comment table created.");
        } catch (SQLException ex)
        {
            System.out.println("ERROR: " + ex.getMessage());
        }
    }
}